package com.cy.uv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cy.uv.entity.Member;
import com.cy.uv.mapper.MemberMapper;
import com.cy.uv.service.MemberService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service

@AllArgsConstructor
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {

    private final MemberMapper memberMapper;
    @Override
    public List<Member> getMembers() {
        return memberMapper.selectList(null);
    }

    @Override
    public Member login(String name, String password) {
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name).eq("password", password);
        return this.getOne(queryWrapper);
    }

    @Override
    public boolean isNameExist(String name) {
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        return this.count(queryWrapper) > 0;
    }
    public boolean isValidUser(String username, String password) {
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username)
                .eq("password", password);

        Member member = memberMapper.selectOne(queryWrapper);
        return member != null;
    }

}
